<?include_once('common/autoload.php');
if(!$_SESSION['memberID']){exit("<script>window.location='dlogin.html'</script>");}
$tpl=Tpl::getLink();
$id=$_REQUEST["id"];
$pri=$_REQUEST["pri"];
$pid=$_REQUEST["pid"];
$title=$_REQUEST["title"];
$_pri=array();
foreach($pid as $v){
	$_pri[$v]=$pri[$v];
}
if($id){
	if(($res=$tpl->upd($id,$_pri))===true){
		echo "<script>alert('修改成功');parent.window.location='addtpl.html?id=".$id."';</script>";
	}
	else{
		echo "<script>alert('".$res."');</script>";
	}
}
else{
	if(filter_var(($res=$tpl->add($_SESSION['memberID'],$title,$_pri)), FILTER_VALIDATE_INT)===false){
		echo "<script>alert('".$res."')</script>";
	}
	else{
		echo "<script>alert('添加成功。');parent.window.history.go(-2);</script>";//parent.window.opener=null;parent.window.close();
	}
}
?>